package com.eascs.spider.ant.schdule.monitor;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.eascs.spider.ant.schdule.dispatcher.Dispatcher;
import com.eascs.spider.ant.schdule.register.RegisterCentre;

/**
 * 监控器
 * @author hzp
 *
 */
@Component
public class Monitor {

	private static Logger logger = LoggerFactory.getLogger(Monitor.class);
	
	@Autowired
	Dispatcher dispatcher;
	
	@Autowired
	RegisterCentre registerCentre;
	
	public void start(){
		ScheduledExecutorService  executors = Executors.newScheduledThreadPool(1);
		executors.scheduleAtFixedRate(new Runnable() {
			
			@Override
			public void run() {
				logger.info("任务队列大小:{} , 工作节点数量:{}" , dispatcher.taskSize() , registerCentre.getWorkers().size());
			}
		}, 1, 120, TimeUnit.SECONDS);
	}
}
